import Vue from 'vue'
import VueRouter from 'vue-router'
// 引入登录组件
// import Login from '../views/Login'
const Login = () => import(/* webpackChunkName: "login_home_welcome" */ '../views/Login')
// 引入首页组件
// import Home from '../views/Home'
const Home = () => import(/* webpackChunkName: "login_home_welcome" */ '../views/Home')
// 引用欢迎组件
// import Welcome from '../views/Welcome.vue'
const Welcome = () => import(/* webpackChunkName: "login_home_welcome" */ '../views/Welcome.vue')

// 引用用户管理组件
// import Users from '../views/Users/Users.vue'
const Users = () => import(/* webpackChunkName: "Users_Roles_Rights" */ '../views/Users/Users.vue')
// 引用角色列表组件
// import Roles from '../views/Rights/Roles.vue'
const Roles = () => import(/* webpackChunkName: "Users_Roles_Rights" */ '../views/Rights/Roles.vue')
// 引入权限列表组件
// import Rights from '../views/Rights/Rights.vue'
const Rights = () => import(/* webpackChunkName: "Users_Roles_Rights" */ '../views/Rights/Rights.vue')

// 引入商品管理分类组件
// import Categories from '../views/goods/Categories.vue'
const Categories = () => import(/* webpackChunkName: "Categories_Params" */ '../views/goods/Categories.vue')
// 引入商品分类参数组件
// import Params from '../views/goods/Params.vue'
const Params = () => import(/* webpackChunkName: "Categories_Params" */ '../views/goods/Params.vue')

// 引入商品列表组件
// import List from '../views/goods/List.vue'
const List = () => import(/* webpackChunkName: "List_Add_Edite" */ '../views/goods/List.vue')
// 引入添加商品组件
// import Add from '../views/goods/Add.vue'
const Add = () => import(/* webpackChunkName: "List_Add_Edite" */ '../views/goods/Add.vue')
// 引入编辑商品组件
// import Edite from '../views/goods/Edite.vue'
const Edite = () => import(/* webpackChunkName: "List_Add_Edite" */ '../views/goods/Edite.vue')

// 引入订单列表组件
// import Order from '../views/order/Order.vue'
const Order = () => import(/* webpackChunkName: "Order_Report" */ '../views/order/Order.vue')
// 引入数据报表组件
// import Report from '../views/Report/Report.vue'
const Report = () => import(/* webpackChunkName: "Order_Report" */ '../views/Report/Report.vue')

// 将 VueRouter 注册到 Vue 实例上
Vue.use(VueRouter)

// 设置路由规则
const routes = [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    {
        path: '/home',
        component: Home,
        // 重定向到 welcome 组件
        redirect: '/welcome',
        children: [
            { path: '/welcome', name: 'welcome', component: Welcome },
            { path: '/users', name: 'users', component: Users },
            { path: '/roles', name: 'roles', component: Roles },
            { path: '/rights', name: 'rights', component: Rights },
            { path: '/categories', name: 'categories', component: Categories },
            { path: '/params', name: 'params', component: Params },
            { path: '/goods', name: 'List', component: List },
            { path: '/goods/add', name: 'add', component: Add },
            { path: '/goods/edite', name: 'edite', component: Edite },
            { path: '/orders', name: 'orders', component: Order },
            { path: '/reports', name: 'reports', component: Report },
        ]
    },
]

// 创建路由实例
const router = new VueRouter({
    routes,
    // mode: 'history'
})

// 配置全局前置守卫
// router.beforeEach((to, from, next) => {
//     // 如果浏览器的 hash 值为 /login
//     if (to.path === '/login') {
//         // next() 方法表示可以去访问
//         return next()
//     }

//     // 获取 token
//     const token = localStorage.getItem('token')
//     // 如果没有 token
//     if (!token) {
//         // 跳转到登录路由界面
//         return next('/login')
//     }

//     // 如果有 token，可以去访问在地址栏输入的路由地址
//     next()
// })

export default router
